package view;

import java.awt.*;
import java.util.*;

import javax.swing.*;

import view.CommonView.CommonJFrame;
import view.CommonView.CommonJPanel;


/**
 * @Author: Lin Hongwei
 * @LastEditors: Lin Hongwei
 * @email: 1365755396@qq.com
 * @CSDN: https://blog.csdn.net/weixin_45429409
 * @Description:系统主操作系界面
 *
 */
public class MainView extends CommonJFrame {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	// 创建单例模式
	public static MainView instance = new MainView();
	private String[] menuArr = { "基础维护", "借阅管理", "查询管理", "系统管理" };
	private String[][] menuItemArr = { { "图书维护", "读者维护", "类别维护" }, { "借书", "还书" }, { "图书查询" },
			{ "修改密码", "退出系统" } };
	private String[][][] childItemArr = { { { "添加图书", "删除与修改图书" }, { "添加读者", "删除与修改读者" }, { "添加类别", "删除与修改类别" } }, {},
			{}, {} };
	private static JPanel contentPane;

	public MainView() {
		setSize(900, 700);
		setLocationRelativeTo(null);// 设置相对于哪个组件的位置（null相当于屏幕中央）
		setFont(new Font("微软雅黑", Font.BOLD, 20));
		// 2. 设置菜单项
		HashMap<String, String[]> menuMap = new HashMap<String, String[]>();
		for (int i = 0; i < menuArr.length; i++) {
			menuMap.put(menuArr[i], menuItemArr[i]);
		}
		JMenuBar menuBar = new JMenuBar();
		menuBar.setBackground(new Color(246, 246, 246));
//		menuBar.setOpaque(false);
//		MainView.setMenuBarList(menuBar, menuMap, menuArr);// 调用封装的设置菜单项方法
		MainView.setMenuBarTowList(menuBar, menuArr, menuItemArr, childItemArr);
		setJMenuBar(menuBar);// 设置菜单栏

		// 2.初始化面板
		contentPane = new CommonJPanel(CommonJPanel.TYPE_BG);
//		contentPane.setLayout(new FlowLayout(FlowLayout.CENTER, 0, 50));
		contentPane.setLayout(new BorderLayout());
		contentPane.setBackground(new Color(255, 255, 255));
		setContentPane(contentPane);


	}

	/**
	 * 显示对应的画面
	 */
	public static void setView(JPanel jPanel) {
		contentPane.removeAll();//删除全部
		contentPane.repaint();//重绘面板
		if(jPanel!=null)contentPane.add(jPanel);
		contentPane.revalidate();//重新布局面板
	}

	public static JPanel getContentJPane() {
		return contentPane;
	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
